import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 解决：Uncaught (in promise) NavigationDuplicated
const originalPush = Router.prototype.push
const originalReplace = Router.prototype.replace

Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(e => e)
}

Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(e => e)
}

import home from '@/router/modules/home'
import { error401, error404 } from '@/router/modules/errorPage'
import apps from '@/router/modules/app'

export const constantRoutes = [
  error404,
  error401,
  home,
  ...apps

]

export const asyncRoutes = [

]

const createRouter = () => new Router({
  base: window.__MICRO_APP_BASE_ROUTE__ || '/',
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()
export default router
